package com.example.pkmedical.Fragments.rollover;

import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.example.pkmedical.Base.BaseFragment;
import com.example.pkmedical.R;

import butterknife.BindView;
import butterknife.OnClick;

public class RolloverLowFragment extends BaseFragment {

    @BindView(R.id.rollover_center_button_text)
    TextView rolloverCenterButtonText;
    @BindView(R.id.rollover_center_button)
    RelativeLayout rolloverCenterButton;
    private PopupWindow YesNoPop;
    private boolean nowType = false;

    @Override
    public int setLayoutId() {
        return R.layout.fragment_rollover_low;
    }

    @Override
    public void findViewById(View view) {

    }

    @Override
    public void setViewData(View view) {

    }

    @Override
    public void setClickEvent(View view) {

    }

    /**
     * 侧翻选择器
     */
    private void initYesNoWindow() {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_yes_no_layout, null);
        RelativeLayout tv_yes = view.findViewById(R.id.rollover_item_yes);
        RelativeLayout tv_no = view.findViewById(R.id.rollover_item_no);
        if (nowType) {
            tv_yes.setVisibility(View.GONE);
        } else {
            tv_no.setVisibility(View.GONE);
        }

        tv_yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rolloverCenterButtonText.setText(R.string.rollover_select_yes);
                nowType = true;
                YesNoPop.dismiss();
            }
        });
        tv_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rolloverCenterButtonText.setText(R.string.rollover_select_no);
                nowType = false;
                YesNoPop.dismiss();
            }
        });
        YesNoPop = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        YesNoPop.setFocusable(true);
        YesNoPop.setOutsideTouchable(true);
        YesNoPop.setBackgroundDrawable(new ColorDrawable());
        YesNoPop.showAsDropDown(rolloverCenterButton);

    }

    @OnClick({R.id.rollover_center_button_text, R.id.rollover_center_button})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rollover_center_button_text:
                break;
            case R.id.rollover_center_button:
                initYesNoWindow();
                break;
        }
    }
}
